package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class DepartmentDAO implements DaoInterface<Department> {
	private ArrayList<Department> arList;
	public DepartmentDAO(ArrayList<Department> arList){
		this.arList=arList;
	}
	@Override
	public void additem(Department item) {
		arList.add(item);
	}
	@Override
	public Department searchitem(Department item) {
		if(arList.contains(item)){
			return arList.get(arList.indexOf(item));
		}else{
			return null;
		}
	}
	@Override
	public void reitem(Department item) {
		arList.set(arList.indexOf(item), item);

	}

	@Override
	public void delitem(Department item) {
		if(arList.contains(item)){//포함되어있다면 그값을 가져와서 삭제한다
			arList.remove(arList.indexOf(item));}
			else{
				System.out.println("해당 학생 정보 없음");
			}
	}
	@Override
	public void prnList() {
		prnHeader();
		for(Department dept:arList){
			System.out.println(dept);
		}
	}
	@Override
	public void prnHeader() {
		String header=String.format("%3s\t%5s\t%3s",
				"학과번호", "학과명", "위치");
		System.out.println(header);
	}
}
